package com.asia5b.a5bmall.same.adapter

import com.asia5b.a5bmall.resource.ResString
import com.asia5b.a5bmall.same.R
import com.asia5b.a5mall.middleware.model.member.UserCouponModel

import com.asia5b.a5mall.middleware.utils.CurrencyPriceBuilder3
import com.asia5b.a5mall.middleware.utils.WTimeUtils
import com.asia5b.a5mall.middleware.utils.judge
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/3/21.
 * 提交订单中的优惠券选择
 */
class OrderCouponAdapter(list: ArrayList<UserCouponModel>) :
        BaseQuickAdapter<UserCouponModel, BaseViewHolder>(R.layout.item_orderplace_coupon_adapter, list) {
    override fun convert(helper: BaseViewHolder, item: UserCouponModel) {
        var spannableString = CurrencyPriceBuilder3().run {
            price = item.amount
            priceList = item.amount_list
            buildPriceText()
        }
        //优惠额度
        helper.setText(R.id.tv_couponlist_price, spannableString)

        spannableString = CurrencyPriceBuilder3().run {
            price = item.coupon_threshold_price
            priceList = item.coupon_threshold_price_list
            buildPriceText()
        }
        //优惠要求额度
        helper.setText(R.id.tv_couponlist_price_min, String.format(ResString.get(R.string.满_数2_元可使用), spannableString))

        val endTime = WTimeUtils.format("${item.end_time * 1000}", WTimeUtils.text_yyyy_MM_dd)
        helper.setText(R.id.tv_couponlist_endtime, String.format(ResString.get(R.string.有效期至_数), endTime))

        helper.setText(R.id.tv_couponlist_use_now, (item.selected != 1).judge(ResString.get(R.string.立即使用), ResString.get(R.string.放弃使用)))


    }
    init {
        addChildClickViewIds(R.id.tv_couponlist_use_now)
    }
}